package com.imu.purse.modules.trade.dao;

import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.imu.core.base.BaseMapper;
import com.imu.purse.modules.trade.entity.PriequityEntity;

/**
 * IMU转账日志表
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2018-07-01 16:21:08
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface PriequityMapper extends BaseMapper<PriequityEntity>
{
	/**
	 * 根据key，查询value
	 */
	@Select({
		"<script>",
		    "SELECT sum(buy_num)",
		    "FROM imu_priequity ",
		    "WHERE `user_id` = #{userId} and `type` = #{t}",
	    "</script>"
	})
	public BigDecimal sumBuyNum(@Param("userId") final Long userId, @Param("t") final Integer t);
	
	/**
     * 分页查询
     * @param pageNo 页号
     * @param pageSize 每页显示记录数
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"user_id, ",
					"buy_num, ",
					"plus_num, ",
					"pay_money, ",
					"pay_bj, ",
					"pay_imu, ",
					"type, ",
					"state, ",
					"create_time, ",
					"update_time",
		    "FROM imu_priequity ",
		    "WHERE 1 = 1 ",
			"<when test = 'userId != null'>",
		    	"AND `user_id` = #{userId}",
		    "</when>",
		    "<when test = 'state != null'>",
		    	"AND `state` = #{state}",
		    "</when>",
		    "<when test = 'sts != null'>",
		    	"AND time_create &gt;= #{sts}",
		    "</when>",
		    "<when test = 'ets != null'>",
				"AND time_create &lt;= #{ets}",
			"</when>",
		    "ORDER BY time_create DESC",
    	"</script>"
	})
    public List<PriequityEntity> findByPage(final PriequityEntity entity);	
}
